import type { ChartsConfig, DataType, EchartsOptions, SeriesOption } from '../types/charts'

const createPieOption = (chartOptions: EchartsOptions, options: ChartsConfig, data: DataType) => {
  const series = createSeries(options, data)
  if (series.length > 0) {
    chartOptions.series = series
  }
  return chartOptions
}

// 生成series部分
const createSeries = (options: ChartsConfig, data: DataType) => {
  let series = []
  const opt = (options.series as SeriesOption) || {}
  series = [
    {
      type: 'pie',
      name: opt.name || '',
      data: data,
      radius: opt.radius || '60%',
      center: opt.center || ['50%', '50%'],
    },
  ]
  return series
}
export default createPieOption
